package cn.dnui_zzh807.dnuifood_16110100807.SomethingElse;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import java.util.List;

import cn.dnui_zzh807.dnuifood_16110100807.R;
import cn.dnui_zzh807.dnuifood_16110100807.adapter.PurchaseAdapter;
import cn.dnui_zzh807.dnuifood_16110100807.bean.CommentInfo;
import cn.dnui_zzh807.dnuifood_16110100807.listener.OnRetrofitListener;
import cn.dnui_zzh807.dnuifood_16110100807.model.UserModel;

public class UserPurchase extends AppCompatActivity implements OnRetrofitListener<List<CommentInfo>> {
    private RecyclerView recyclerView;
    private String user_id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_purchase);
        user_id=getIntent().getStringExtra("user_id");
        recyclerView = (RecyclerView)findViewById(R.id.purchase_recycleview);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        initData();
    }

    private void initData(){
        UserModel userModel = new UserModel();
        userModel.getAllOrdersByUser(user_id,this);
    }

    @Override
    public void onSuccess(List<CommentInfo> comments, int flag) {
        PurchaseAdapter purchaseAdapter = new PurchaseAdapter(this,comments);
        recyclerView.setAdapter(purchaseAdapter);
    }

    @Override
    public void onFail() {
        Toast.makeText(UserPurchase.this,"网络错误"+user_id,Toast.LENGTH_SHORT).show();
    }
}
